import { GTRequestInterface } from './types'
import { Toast } from 'vant'
import { errorResult } from '../Axios'
import { GTAxiosOptions } from '../types'

class GTRequest implements  GTRequestInterface {

  axiosOptions: GTAxiosOptions

  constructor(options: GTAxiosOptions){
    this.axiosOptions = options
  }

  isSuccess(responseData: any){
    const { code, Code } = responseData
    if(code === 200 || Code === 0){
      return true
    }
    return false
  }

  commonFail(responseData: any){
    const { desc, msg, code } = responseData

    // // 特殊code错误处理
    // if (code === 401) {
    //   return errorResult
    // }

    if(code === 20103 || code === 401) { // 会话过期
      this.axiosOptions.loginStatusCatch && this.axiosOptions.loginStatusCatch(code)
    }else{
      if (desc || msg) {
        Toast.fail(desc || msg)
      }
    }

    return errorResult
  }

  addTokenToRequest(){

  }
}

export default GTRequest
